package me.mcx.mcx.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import me.mcx.common.annotation.Log;
import me.mcx.common.core.controller.BaseController;
import me.mcx.common.core.domain.AjaxResult;
import me.mcx.common.core.page.TableDataInfo;
import me.mcx.common.enums.BusinessType;
import me.mcx.common.utils.poi.ExcelUtil;
import me.mcx.mcx.domain.McxNews;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import me.mcx.mcx.service.IMcxNewsService;

/**
 * 新闻信息管理Controller
 * 
 * @author mcx
 * @date 2024-09-21
 */
@RestController
@RequestMapping("/mcx/news")
public class McxNewsController extends BaseController
{
    @Autowired
    private IMcxNewsService mcxNewsService;

    /**
     * 查询新闻信息管理列表
     */
    @PreAuthorize("@ss.hasPermi('mcx:news:list')")
    @GetMapping("/list")
    public TableDataInfo list(McxNews mcxNews)
    {
        startPage();
        List<McxNews> list = mcxNewsService.selectMcxNewsList(mcxNews);
        return getDataTable(list);
    }

    /**
     * 导出新闻信息管理列表
     */
    @PreAuthorize("@ss.hasPermi('mcx:news:export')")
    @Log(title = "新闻信息管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, McxNews mcxNews)
    {
        List<McxNews> list = mcxNewsService.selectMcxNewsList(mcxNews);
        ExcelUtil<McxNews> util = new ExcelUtil<McxNews>(McxNews.class);
        util.exportExcel(response, list, "新闻信息管理数据");
    }

    /**
     * 获取新闻信息管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('mcx:news:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(mcxNewsService.selectMcxNewsById(id));
    }

    /**
     * 新增新闻信息管理
     */
    @PreAuthorize("@ss.hasPermi('mcx:news:add')")
    @Log(title = "新闻信息管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody McxNews mcxNews)
    {
        return toAjax(mcxNewsService.insertMcxNews(mcxNews));
    }

    /**
     * 修改新闻信息管理
     */
    @PreAuthorize("@ss.hasPermi('mcx:news:edit')")
    @Log(title = "新闻信息管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody McxNews mcxNews)
    {
        return toAjax(mcxNewsService.updateMcxNews(mcxNews));
    }

    /**
     * 删除新闻信息管理
     */
    @PreAuthorize("@ss.hasPermi('mcx:news:remove')")
    @Log(title = "新闻信息管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mcxNewsService.deleteMcxNewsByIds(ids));
    }
}
